package com.dv.web.controller.equipment;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.dv.common.utils.DateUtils;
import com.dv.driverless.domain.EquipmentFence;
import com.dv.driverless.service.IEquipmentFenceService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.dv.common.annotation.Log;
import com.dv.common.core.controller.BaseController;
import com.dv.common.core.domain.AjaxResult;
import com.dv.common.enums.BusinessType;
import com.dv.common.utils.poi.ExcelUtil;
import com.dv.common.core.page.TableDataInfo;

/**
 * 安全围栏Controller
 *
 * @author ruoyi
 * @date 2023-04-06
 */
@RestController
@RequestMapping("/equipment/fence")
public class EquipmentFenceController extends BaseController
{
    @Autowired
    private IEquipmentFenceService equipmentFenceService;

    /**
     * 查询安全围栏列表
     */
    @PreAuthorize("@ss.hasPermi('system:fence:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentFence equipmentFence)
    {
        startPage();
        List<EquipmentFence> list = equipmentFenceService.selectEquipmentFenceList(equipmentFence);
        return getDataTable(list);
    }

    /**
     * 导出安全围栏列表
     */
    @PreAuthorize("@ss.hasPermi('system:fence:export')")
    @Log(title = "安全围栏", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentFence equipmentFence)
    {
        List<EquipmentFence> list = equipmentFenceService.selectEquipmentFenceList(equipmentFence);
        ExcelUtil<EquipmentFence> util = new ExcelUtil<EquipmentFence>(EquipmentFence.class);
        util.exportExcel(response, list, "安全围栏数据");
    }

    /**
     * 获取安全围栏详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:fence:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentFenceService.selectEquipmentFenceById(id));
    }

    /**
     * 新增安全围栏
     */
    @PreAuthorize("@ss.hasPermi('system:fence:add')")
    @Log(title = "安全围栏", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentFence equipmentFence)
    {
        equipmentFence.setCreateDate(DateUtils.getNowDate());
        return toAjax(equipmentFenceService.insertEquipmentFence(equipmentFence));
    }

    /**
     * 修改围栏状态
     */
    @Log(title = "安全围栏",businessType = BusinessType.UPDATE)
    @PutMapping("/changeStatus")
    public AjaxResult changeFenceStatus(@RequestBody EquipmentFence equipmentFence)
    {
        return toAjax(equipmentFenceService.changeEquipmentFence(equipmentFence));
    }

    /**
     * 修改安全围栏
     */
    @PreAuthorize("@ss.hasPermi('system:fence:edit')")
    @Log(title = "安全围栏", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentFence equipmentFence)
    {
        return toAjax(equipmentFenceService.updateEquipmentFence(equipmentFence));
    }

    /**
     * 删除安全围栏
     */
    @PreAuthorize("@ss.hasPermi('system:fence:remove')")
    @Log(title = "安全围栏", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentFenceService.deleteEquipmentFenceByIds(ids));
    }
}
